<h2>Why is this an issue?</h2>
<p>Properties provide a way to enforce <a href="https://en.wikipedia.org/wiki/Encapsulation_(computer_programming)">encapsulation</a> by providing
property procedures that give controlled access to <code>Private</code> fields. However, in classes with multiple fields, it is not unusual that <a
href="https://en.wikipedia.org/wiki/Copy-and-paste_programming">copy-and-paste</a> is used to quickly create the needed properties, which can result
in the wrong field being accessed by the property procedures.</p>
<pre>
Class C
    Private _x As Integer
    Private _Y As Integer

    Public ReadOnly Property Y As Integer
        Get
            Return _x ' Noncompliant: The returned field should be '_y'
        End Get
    End Property
End Class
</pre>
<p>This rule raises an issue in any of these cases:</p>
<ul>
  <li> A get procedure does not access the field with the corresponding name. </li>
  <li> A set procedure does not update the field with the corresponding name. </li>
</ul>
<p>For simple properties, it is better to use <a
href="https://learn.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/procedures/auto-implemented-properties">auto-implemented
properties</a> (VB.NET 10.0 or later).</p>
<p>Field and property names are compared as case-insensitive. All underscore characters are ignored.</p>
<h2>How to fix it</h2>
<h3>Code examples</h3>
<h4>Noncompliant code example</h4>
<pre data-diff-id="1" data-diff-type="noncompliant">
Public Class Sample

    Private _x As Integer
    Private _y As Integer

    Public Property Y As Integer
        Get
            Return _x   ' Noncompliant: field '_y' is not used in the return value
        End Get
        Set(value As Integer)
            _x = value  ' Noncompliant: field '_y' is not updated
        End Set
    End Property

End Class
</pre>
<h4>Compliant solution</h4>
<pre data-diff-id="1" data-diff-type="compliant">
Public Class Sample

    Private _x As Integer
    Private _y As Integer

    Public Property Y As Integer
        Get
            Return _y
        End Get
        Set(value As Integer)
            _y = value
        End Set
    End Property

End Class
</pre>
<h2>Resources</h2>
<ul>
  <li> Microsoft Learn: <a
  href="https://learn.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/procedures/property-procedures">Property Procedures
  (Visual Basic)</a> </li>
</ul>

